﻿Imports MySoft.Map.Data
Imports System.Data
Imports System.Net
Imports System.Xml
Imports System.Data.SqlClient
Imports System.Text
Imports System.IO
Imports Mysoft.ZipLib.Zip
Imports Mysoft.ZipLib.Checksums
Imports Mysoft.Map.Excel

Partial Class Cwjk_XMLHTTP
    Inherits System.Web.UI.Page

    '导出账套设置
    Function ExportCwZtSet(ByVal strCwZtGUID As String, ByVal strApplication As String) As String
        '0、变量定义和初始化
        Dim strPath As String = ""
        Dim strXml As String = ""
        Dim strXmlFileName As String = "账套设置数据文件.xml"
        Dim strZipFileName As String = "账套设置数据包" & Format(Now(), "yyyyMMdd") & ".zip"
        Dim strXmlFileFullName, strZipFileFullName As String

        '1、在根目录（Map\TempFiles）下创建存放xml文件的临时目录，以账套GUID命名
        strPath = Server.MapPath("\TempFiles\" & strCwZtGUID)
        If Not IO.Directory.Exists(strPath) Then
            IO.Directory.CreateDirectory(strPath)
        End If

        '2、根据这个账套的数据，创建XML文件，放到所创建的目录下

        '获取文件全名
        strXmlFileFullName = strPath & "\" & strXmlFileName
        strZipFileFullName = strPath & "\" & strZipFileName

        '生成数据xml串
        Try
            strXml = GetZtSetXml(strCwZtGUID, strApplication)
        Catch ex As Exception
            Return ex.ToString()
        End Try

        '删除已经存在的xml文件
        If File.Exists(strXmlFileFullName) Then
            File.Delete(strXmlFileFullName)
        End If

        Dim doc As XmlDocument = New XmlDataDocument
        doc.LoadXml(strXml)
        doc.Save(strXmlFileFullName)

        '3、把这个目录下的文件创建为zip文件
        '删除已经存在的zip文件
        If File.Exists(strZipFileFullName) Then
            File.Delete(strZipFileFullName)
        End If

        '生成zip文件
        Return CreateZip(strPath, strZipFileFullName)

        '以下两步在download页面中完成
        '4、下载zip文件
        '5、删除所创建的目录和目录下的文件


    End Function

    '生成账套数据
    Function GetZtSetXml(ByVal strCwZtGUID As String, ByVal strApplication As String) As String
        If strCwZtGUID = "" Then Return ""

        Dim dtCwzt, dtTmpMain, dtTmpSub As DataTable
        Dim drCwzt, drTmpMain, drTmpSub As DataRow
        Dim sbXml As New StringBuilder
        Dim strFields, strSql As String
        '表串，格式“,表名称|子表名称|字表和主表关联字段,”
        Dim strSchema As String = "p_CwjkPzz,p_CwjkHsxm,p_CwjkKjkm|p_CwjkKjkm2Hsxm|KmTypeGUID,p_CwjkOperTypeRule|p_CwjkPzEntryRule|OperTypeGUID"
        Dim arrSchema(), arrTmp() As String
        Dim iArr As Integer
        Dim strTbName0, strTbName, strTbNameSub As String

        arrSchema = strSchema.Split(",")

        sbXml.Append("<?xml version='1.0' encoding='gb2312' ?>")
        '账套数据（p_CwjkCwzt）
        strSql = "select * from p_CwjkCwzt where CwztGUID = '" & strCwZtGUID & "'"
        dtCwzt = MyDB.GetDataTable(strSql)
        If dtCwzt.Rows.Count > 0 Then
            drCwzt = dtCwzt.Rows(0)
            sbXml.Append("<Cwzt ")
            strFields = GetFieldsValue(dtCwzt, drCwzt, dtCwzt.Columns.Count)
            sbXml.Append(strFields)
            sbXml.Append(">")
        End If

        '其他表通过循环来实现
        For iArr = 0 To arrSchema.Length - 1
            strTbName0 = arrSchema(iArr)
            strTbName = arrSchema(iArr)
            arrTmp = strTbName0.Split("|")
            If arrTmp.Length > 1 Then
                strTbName = arrTmp(0)
            End If

            '主表数据
            sbXml.Append("<" & strTbName.Replace("p_Cwjk", "") & ">")
            strSql = "SELECT * FROM " & strTbName & " WHERE CwztGUID = '" & strCwZtGUID & "'"
            dtTmpMain = MyDB.GetDataTable(strSql)
            If dtTmpMain.Rows.Count > 0 Then
                For Each drTmpMain In dtTmpMain.Rows
                    '拼每一行的数据
                    sbXml.Append("<Row ")
                    strFields = GetFieldsValue(dtTmpMain, drTmpMain, dtTmpMain.Columns.Count)
                    sbXml.Append(strFields)
                    sbXml.Append(">")

                    If arrTmp.Length > 1 Then
                        '子表数据，方式和主表一样
                        strTbNameSub = arrTmp(1)
                        sbXml.Append("<" & strTbNameSub.Replace("p_Cwjk", "") & ">")
                        strSql = "SELECT * FROM " & strTbNameSub & " WHERE CwztGUID = '" & strCwZtGUID & "' AND " & arrTmp(2) & " ='" & drTmpMain(arrTmp(2)).ToString() & "'"
                        dtTmpSub = MyDB.GetDataTable(strSql)

                        If dtTmpSub.Rows.Count > 0 Then
                            For Each drTmpSub In dtTmpSub.Rows
                                sbXml.Append("<Row ")
                                strFields = GetFieldsValue(dtTmpSub, drTmpSub, dtTmpSub.Columns.Count)
                                sbXml.Append(strFields)
                                sbXml.Append("></Row>")
                            Next
                        End If

                        sbXml.Append("</" & strTbNameSub.Replace("p_Cwjk", "") & ">")
                    End If

                    sbXml.Append("</Row>")
                Next
            End If

            sbXml.Append("</" & strTbName.Replace("p_Cwjk", "") & ">")
        Next


        sbXml.Append("</Cwzt>")

        Return sbXml.ToString()
    End Function
    '功能：生成某一行的字段值串 
    '格式：fieldName='fieldValue'
    Function GetFieldsValue(ByVal dtTmp As DataTable, ByVal drTmp As DataRow, ByVal iColumns As Integer) As String
        If drTmp Is Nothing Then Return ""

        Dim index As Integer
        Dim strRtn As String = ""
        For index = 0 To iColumns - 1
            strRtn &= dtTmp.Columns(index).ColumnName & "='" & MySoft.PubProject.Business.PublicMNG.ReplaceXmlChar(drTmp.Item(index).ToString()) & "' "
        Next

        Return strRtn
    End Function

    '生成zip文件
    Function CreateZip(ByVal strPath As String, ByVal strZipFileFullName As String) As String
        '读取压缩包文件
        Dim iBs As Integer = 0
        Dim arrFiles() As String = IO.Directory.GetFiles(strPath)
        Dim strFiles As String

        Dim i As Integer
        Dim objCrc32 As New Crc32
        Dim strmZipOutputStream As ZipOutputStream
        Dim fs As FileStream

        '压缩数据流
        strmZipOutputStream = New ZipOutputStream(File.Create(strZipFileFullName))

        Try
            For i = 0 To arrFiles.Length - 1        '循环压进压缩包
                If File.Exists(arrFiles(i)) Then
                    Dim bytes() As Byte
                    fs = New FileStream(arrFiles(i), FileMode.Open, FileAccess.Read)

                    ReDim bytes(fs.Length - 1)
                    fs.Read(bytes, 0, fs.Length)            '数据流读入数组
                    fs.Close()

                    '设置压缩率     0 -- 不压缩
                    '               9 -- 最大压缩比
                    strmZipOutputStream.SetLevel(9)
                    '被压缩文件接口信息
                    Dim objZipEntry As ZipEntry = New ZipEntry(Path.GetFileName(arrFiles(i)))
                    '存放在压缩文件中的文件名
                    objZipEntry.DateTime = DateTime.Now                         '压缩时间
                    objZipEntry.Size = bytes.GetLength(0)                   '被压缩文件大小
                    objCrc32.Reset()
                    objCrc32.Update(bytes)
                    objZipEntry.Crc = objCrc32.Value                            '冗余校验值

                    strmZipOutputStream.PutNextEntry(objZipEntry)
                    strmZipOutputStream.Write(bytes, 0, bytes.Length)
                    iBs = iBs + 1

                    '删除xml文件
                    File.Delete(arrFiles(i))
                End If

            Next
        Catch ex As Exception
            'fs.Close()

            Return ex.ToString()

        End Try

        '关闭
        strmZipOutputStream.Finish()
        strmZipOutputStream.Close()
        If iBs <> 0 Then
            Return strZipFileFullName
        Else
            Return "FAILCREATE"
        End If

    End Function

    '引入默认账套设置信息
    Function ImportDefaultCwZtSet(ByVal strCwztGUID As String, ByVal strApplication As String) As String
        Dim myImport As New Cwjk_Import
        Dim strAlert As String

        Dim strPath, strDefaultZipFileName, strZipFileName, strXmlFileName As String
        strDefaultZipFileName = Server.MapPath("\PubProject\Cwjk\Files\") & IIf(strApplication = "0101", "售楼默认账套设置数据包.zip", "成本默认账套设置数据包.zip")

        '校验默认设置数据包是否存在
        If Not File.Exists(strDefaultZipFileName) Then
            Return "默认设置数据包不存在！"
        End If

        '0、在\TempFiles目录下创建临时目录，名称为 “Import”+以该账套的GUID串
        strPath = Server.MapPath("\TempFiles")

        '1、把默认账套设置包文件拷贝到这个目录
        strZipFileName = strPath & "\" & System.Guid.NewGuid.ToString() & ".zip"
        Do While IO.File.Exists(strZipFileName)
            IO.File.Delete(strZipFileName)
        Loop

        IO.File.Copy(strDefaultZipFileName, strZipFileName)

        IO.File.SetAttributes(strZipFileName, IO.FileAttributes.Normal)

        '2、解压zip文件
        strAlert = myImport.Decode(strPath & "\", strZipFileName)
        If strAlert <> "" Then
            myImport.DeleteFiles(strXmlFileName, strZipFileName, strPath)
            Return strAlert
        End If

        '3、读取并处理zip中的xml文件内容
        strXmlFileName = strPath & "\账套设置数据文件.xml"
        strAlert = myImport.GetXmlDate(strXmlFileName, strCwztGUID, strApplication)
        If strAlert <> "" Then
            myImport.DeleteFiles(strXmlFileName, strZipFileName, strPath)
            Return strAlert
        End If

        '4、删除文件
        myImport.DeleteFiles(strXmlFileName, strZipFileName, strPath)

        Return "OK"

    End Function

    '导出会计科目/辅助核算对照信息
    Function ExportKjkmOrHsxmMap() As String
        '0、变量定义和初始化
        Dim strGetType, strBuGUID, strCwztGUID, strProjGUID, strOperObject, strBz, strKmTypeGUID, strApplication, strFilterStr As String
        Dim dtData As DataTable
        Dim myCwjkMng As New MySoft.PubProject.Business.CwjkMNG
        Dim strPath, strFileName, strFileFullName, strTitles, strFields As String
        Dim arrFields() As String

        Dim intMaxRow, intMax, idxRow, idx As Integer
        Dim wb As ExcelWookbook = New ExcelWookbook
        Dim ws As ExcelWorksheet
        Dim cell As ExcelCell
        Dim strValue As String

        strGetType = Request.QueryString("GetType")
        strBuGUID = Session("BUGUID")
        strCwztGUID = Request.QueryString("CwztGUID")
        strProjGUID = Request.QueryString("ProjGUID")
        strOperObject = Request.QueryString("OperObject")
        strBz = Request.QueryString("Bz")
        strKmTypeGUID = Request.QueryString("KmTypeGUID")
        strApplication = Request.QueryString("Application")

        strFilterStr = ""
        If strApplication = "0201" AndAlso strOperObject = "供应商" Then
            strFilterStr = strProjGUID
        End If

        '创建临时目录
        'aobo edit by 2010-07-10 将下载的文件放到\TempFiles\Export目录，平台会自动删除历史无用文件
        strPath = Server.MapPath("\TempFiles\Export")
        If Not IO.Directory.Exists(strPath) Then
            IO.Directory.CreateDirectory(strPath)
        End If


        '1、获取文件名，标题，字段列表
        If strGetType = "KJKM" Then
            If strOperObject = "手工录入" Then
                strFileName = "会计科目(手工录入)对照信息.xls"
                strTitles = "科目代码、科目名称、财务账套GUID、业务标识"
                strFields = "KmCode、KmName、CwztGUID、ObjectGUID"
            Else
                strFileName = "会计科目对照信息.xls"
                strFields = "ObjectCode、ObjectName、KmCode、KmName、CwztGUID、ObjectGUID"

                Select Case strOperObject
                    '销售系统部分
                    Case "房间信息"
                        strTitles = "房间代码、房间名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "楼栋名称"
                        strTitles = "楼栋代码、楼栋名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "预约单"
                        strTitles = "预约排号：预约客户、科目代码、科目名称、财务账套GUID、业务标识"
                        strFields = "ObjectName、KmCode、KmName、CwztGUID、ObjectGUID"
                        Exit Select

                        '成本系统部分，请负责成本部分的同事补充
                    Case "合同类别"
                        strTitles = "合同类别代码、合同类别名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "合同"
                        strTitles = "合同编号、合同名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "部门"
                        strTitles = "部门代码、部门名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "供应商"
                        strTitles = "供应商编号、供应商名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "成本科目"
                        '当项目GUID等于公司GUID时，为中间科目
                        If strProjGUID.ToUpper = strBuGUID.ToUpper Then
                            strTitles = "中间科目代码、中间科目名称、科目代码、科目名称、财务账套GUID、业务标识"
                        Else
                            strTitles = "成本科目代码、成本科目名称、科目代码、科目名称、财务账套GUID、业务标识"
                        End If

                        Exit Select
                End Select

            End If
        Else
            If strOperObject = "手工录入" Then
                strFileName = "辅助核算(手工录入)对照信息.xls"
                strTitles = "核算代码、核算名称、财务账套GUID、业务标识"
                strFields = "HsxmCode、HsxmName、CwztGUID、ObjectGUID"
            Else
                strFileName = "辅助核算对照信息.xls"
                strFields = "ObjectCode、ObjectName、HsxmCode、HsxmName、CwztGUID、ObjectGUID"

                Select Case strOperObject
                    '销售系统部分
                    Case "房间信息"
                        strTitles = "房间代码、房间名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "楼栋名称"
                        strTitles = "楼栋代码、楼栋名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "预约单"
                        strTitles = "预约排号：预约客户、核算代码、核算名称、财务账套GUID、业务标识"
                        strFields = "ObjectName、HsxmCode、HsxmName、CwztGUID、ObjectGUID"
                        Exit Select

                        '成本系统部分，请负责成本部分的同事补充
                    Case "合同类别"
                        strTitles = "合同类别代码、合同类别名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "合同"
                        strTitles = "合同编号、合同名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "部门"
                        strTitles = "部门代码、部门名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "供应商"
                        strTitles = "供应商编号、供应商名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Exit Select
                    Case "成本科目"
                        '当项目GUID等于公司GUID时，为中间科目
                        If strProjGUID.ToUpper = strBuGUID.ToUpper Then
                            strTitles = "中间科目代码、中间科目名称、核算代码、核算名称、财务账套GUID、业务标识"
                        Else
                            strTitles = "成本科目代码、成本科目名称、核算代码、核算名称、财务账套GUID、业务标识"
                        End If

                End Select
            End If
        End If

        'aobo edit by 2010-07-10 将下载的文件名与保存的文件名分开处理，原因为保存的文件名为固定，而存在服务的文件名随机产生
        'strFileFullName = strPath & "\" & strFileName
        strFileFullName = strPath & "\" & System.Guid.NewGuid().ToString() & ".xlsx"


        '2、数据处理
        dtData = myCwjkMng.GetKjkmOrHsxmDT(strGetType, strBuGUID, strCwztGUID, strProjGUID, strOperObject, strBz, strKmTypeGUID, strApplication, strFilterStr)

        If dtData.Rows.Count = 0 Then
            Return ""
        End If

        intMaxRow = dtData.Rows.Count - 1

        ws = wb.Worksheets.Add(strGetType)

        ''第一行

        '第二行
        cell = ws.Cells(0, 0)
        cell.Value = "业务对象"

        '第三行
        cell = ws.Cells(1, 0)
        cell.Value = strOperObject

        '第四行 标题行
        arrFields = strTitles.Split("、")
        intMax = arrFields.Length - 1
        For idx = 0 To intMax
            cell = ws.Cells(2, idx)
            cell.Value = arrFields(idx).ToString()
        Next

        '实际数据
        arrFields = strFields.Split("、")
        For idxRow = 0 To intMaxRow
            For idx = 0 To intMax
                cell = ws.Cells(idxRow + 3, idx)
                cell.Value = dtData.Rows(idxRow).Item(arrFields(idx)).ToString()
            Next
        Next

        '3、保存到excel文件
        wb.SaveXls(strFileFullName)

        '返回文件全名，在down页面输出
        'aobo edit by 2010-07-10 将下载的文件名与保存的文件名分开处理，原因为保存的文件名为固定，而存在服务的文件名随机产生
        Return strFileFullName & "|" & strFileName

    End Function


    '获取需要同步账套的数量
    Function GetNeedToCopyCwztCount() As String

        Dim strRtn As String = ""
        Dim strBUGUID As String = ""
        Dim strCwztGUID As String = ""
        Dim strApplication As String = ""
        Dim strSql As String = ""

        If Request.QueryString("BUGUID") <> Nothing AndAlso Request.QueryString("CwztGUID") <> Nothing AndAlso Request.QueryString("Application") <> Nothing Then
            strBUGUID = Request.QueryString("BUGUID")
            strCwztGUID = Request.QueryString("CwztGUID")
            strApplication = Request.QueryString("Application")

            Try
                strSql = "select count(1) from p_CwjkCwzt as a left join p_CwjkHsxm as b on a.CwztGUID=b.CwztGUID " & _
                            "left join p_CwjkHsxmMap as c on b.HsTypeGUID=c.HsTypeGUID " & _
                            "where a.CwztGUID='" & strCwztGUID & "' and b.OperObject='供应商'"

                If MyDB.GetDataItemInt(strSql) = 0 Then
                    Return "0"
                End If

                strSql = "SELECT DISTINCT f.CwztGUID FROM " & _
                        "( " & _
                        "select b.CwztGUID,a.ObjectGUID from " & _
                        "( " & _
                        "select c.ObjectGUID from p_CwjkCwzt as a " & _
                        "left join p_CwjkHsxm as b on a.CwztGUID=b.CwztGUID " & _
                        "left join p_CwjkHsxmMap as c on b.HsTypeGUID=c.HsTypeGUID " & _
                        "where a.CwztGUID='" & strCwztGUID & "' and b.OperObject='供应商' and (c.HsxmCode<>'' or c.HsxmName<>'') " & _
                        ") a " & _
                        "CROSS JOIN " & _
                        "(select a.CwztGUID from p_CwjkCwzt a left join p_CwjkHsxm as b on a.CwztGUID=b.CwztGUID " & _
                        "where BUGUID='" & strBUGUID & "' and b.OperObject='供应商' and Application='" & strApplication & "' and a.CwztGUID<>'" & strCwztGUID & "' " & _
                        ") b " & _
                        ") f " & _
                        "LEFT JOIN p_CwjkHsxmMap as m on f.CwztGUID=m.CwztGUID and f.ObjectGUID=m.ObjectGUID " & _
                        "WHERE m.HsxmCode is null or (m.HsxmCode='' and m.HsxmName='') "

                Dim dtTemp As DataTable = MyDB.GetDataTable(strSql)

                strRtn = dtTemp.Rows.Count.ToString()

            Catch ex As Exception
                strRtn = "0"
            End Try

        Else
            strRtn = "0"
        End If

        Return strRtn

    End Function

    '将辅助核算数据同步到其它账套
    Function CopyCwjkHsxmMap() As String
        Dim strApplication As String = ""
        Dim strBUGUID As String = ""
        Dim strCwztGUID As String = ""

        If Request.QueryString("Application") <> Nothing AndAlso Request.QueryString("Application").ToString() <> "" Then
            strApplication = Request.QueryString("Application").ToString()
        End If

        If Request.QueryString("BUGUID") <> Nothing AndAlso Request.QueryString("BUGUID").ToString() <> "" Then
            strBUGUID = Request.QueryString("BUGUID").ToString()
        End If

        If Request.QueryString("CwztGUID") <> Nothing AndAlso Request.QueryString("CwztGUID").ToString() <> "" Then
            strCwztGUID = Request.QueryString("CwztGUID").ToString()
        End If


        Dim connectString As String = MyDB.GetSqlConnectionString()
        Dim conn As New SqlClient.SqlConnection(connectString)
        Dim cmd As New SqlClient.SqlCommand
        Dim rtnval As Integer = 0
        Try
            conn.Open()
            cmd.CommandTimeout = 300000000
            cmd.Connection = conn
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "usp_p_CopyCwjkHsxmMap"

            cmd.Parameters.Add(New SqlClient.SqlParameter("@BUGUID", SqlDbType.VarChar, 40))
            cmd.Parameters("@BUGUID").Value = strBUGUID
            cmd.Parameters.Add(New SqlClient.SqlParameter("@CwztGUID", SqlDbType.VarChar, 40))
            cmd.Parameters("@CwztGUID").Value = strCwztGUID
            cmd.Parameters.Add(New SqlClient.SqlParameter("@Application", SqlDbType.VarChar, 10))
            cmd.Parameters("@Application").Value = strApplication

            rtnval = cmd.ExecuteScalar()

        Catch ex As Exception
            Return rtnval
        Finally
            conn.Close()
        End Try
        Return rtnval
    End Function

    '将当前选择的项目添加到当前账套
    Function AddProjectToCwzt() As String

        Dim strRtn As String = "NO|"
        Dim strBUGUID As String = ""
        Dim strCwztGUID As String = ""
        Dim strProjGUIDList As String = ""
        Dim strApplication As String = ""
        Dim strSql As String = ""

        If Request.QueryString("BUGUID") <> Nothing AndAlso Request.QueryString("CwztGUID") <> Nothing AndAlso Request.QueryString("ProjGUIDList") <> Nothing AndAlso Request.QueryString("Application") <> Nothing Then
            strBUGUID = Request.QueryString("BUGUID").ToString()
            strCwztGUID = Request.QueryString("CwztGUID").ToString()
            strProjGUIDList = Request.QueryString("ProjGUIDList").ToString().Replace(",", "','")
            strApplication = Request.QueryString("Application").ToString()

            Try

                If strProjGUIDList <> "" Then

                    strSql = "SELECT ProjName FROM p_CwjkProject as a left join p_Project as b on a.ProjGUID=b.ProjGUID " & _
                            "left join p_CwjkCwzt as c on a.CwztGUID=c.CwztGUID " & _
                            "WHERE a.ProjGUID in ('" & strProjGUIDList & "') and c.Application = '" & strApplication & "'"

                    Dim dtTempTable As DataTable = MyDB.GetDataTable(strSql)

                    If dtTempTable.Rows.Count > 0 Then

                        strRtn = "NO|"
                        Dim i As Integer
                        For i = 0 To dtTempTable.Rows.Count - 1
                            strRtn &= dtTempTable.Rows(i).Item("ProjName").ToString() + "，"
                        Next
                        strRtn = strRtn.Remove(strRtn.Length - 1)
                    Else

                        strSql = "INSERT INTO p_CwjkProject (CwjkProjGUID, BUGUID, CwztGUID, ProjGUID) " & _
                            "(select newid(), '" & strBUGUID & "', '" & strCwztGUID & "', ProjGUID from p_Project where ProjGUID in ('" & strProjGUIDList & "'))"
                        Dim intCount As Integer = MyDB.ExecuteSQL(strSql)
                        If intCount > 0 Then
                            strRtn = "YES|" & intCount.ToString()
                        End If

                    End If

                End If

            Catch ex As Exception
                strRtn = "NO|"
            End Try

        Else
            strRtn = "NO|"
        End If

        Return strRtn

    End Function
End Class
